package com.gxa.modules.sys.controller;

import com.github.pagehelper.PageInfo;
import com.gxa.common.utils.AssertUtils;
import com.gxa.common.utils.PageUtils;
import com.gxa.modules.community.util.Result;
import com.gxa.modules.sys.entity.*;
import com.gxa.modules.sys.service.HouseLabelService;
import com.gxa.modules.sys.service.OperationLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(tags = "操作日志 接口")
@RestController
@Slf4j
public class OperationLogController {
    @Autowired
    private OperationLogService operationLogService ;

    @ApiOperation(value="操作日志 (查询条件  操作人)")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query",name = "page",value ="当前是第几页",dataType ="int"),
            @ApiImplicitParam(paramType = "query",name = "limit",value ="每页显示多少条",dataType ="int"),
            @ApiImplicitParam(paramType = "query",name = "employeeName",value = "操作人",dataType ="String"),
    })
    @GetMapping("/operationLog/list")
    public Result<List<OperationLog>> operationLogList(@RequestParam Map<String,Object> params){
        log.info("----params-----{}----",params);
        AssertUtils.isBlank(String.valueOf(params), "字符串不为能空");

        Result<List<OperationLog>> r = Result.success();
        try {
            PageInfo<OperationLog> pageInfo = operationLogService.queryOperationLog(params);
            r = Result.success(pageInfo.getList(),pageInfo.getTotal());
        }catch (Exception e){
            e.printStackTrace();
            r = Result.failed();
        }
        return r;
    }

    @ApiOperation(value="操作日志 添加")
    @PostMapping("/operationLog/add")
    public com.gxa.common.utils.Result<PageUtils> operationLogAdd(@RequestBody OperationLogAdd operationLogAdd) {
        log.info("----operationLogAdd-----{}----", operationLogAdd);
        AssertUtils.isBlank(String.valueOf(operationLogAdd), "字符串不为能空");
        this.operationLogService.addOperationLog(operationLogAdd);
        return new com.gxa.common.utils.Result<PageUtils>().ok();
    }

    @ApiOperation(value="操作日志 修改")
    @PutMapping("/operationLog/update")
    public com.gxa.common.utils.Result<PageUtils> operationLogUpdate(@RequestBody OperationLogUpdate operationLogUpdate) {
        log.info("----houseLabelUpdate-----{}----", operationLogUpdate);
        AssertUtils.isBlank(String.valueOf(operationLogUpdate), "字符串不为能空");
        this.operationLogService.updateOperationLog(operationLogUpdate);
        return new com.gxa.common.utils.Result<PageUtils>().ok();
    }

    @ApiOperation(value="操作日志 删除")
    @DeleteMapping("/operationLog/delete")
    public com.gxa.common.utils.Result<PageUtils> operationLogDalete(@RequestBody Integer[] ids) {
        log.info("----ids-----{}----", ids);
        AssertUtils.isBlank(String.valueOf(ids), "字符串不为能空");
        for (Integer id:ids){
            System.out.println(id);
            this.operationLogService.deleteOperationLog(id);
        }
        return new com.gxa.common.utils.Result<PageUtils>().ok();
    }

}
